package com.aidong.web.controller.card;

/**
 * Created by john on 16-11-3.
 */
import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.CardManyUserDao;
import com.aidong.dao.wills.CardQuantityDao;
import com.aidong.dao.wills.CardShopLevelDao;
import com.aidong.dao.wills.CardTimeLimitDao;
import com.aidong.dao.wills.CardTypeCodeDao;
import com.aidong.dao.wills.DicTranCodeDao;
import com.aidong.model.wills.CardManyUser;
import com.aidong.model.wills.CardQuantity;
import com.aidong.model.wills.CardShopLevel;
import com.aidong.model.wills.CardTimeLimit;
import com.aidong.model.wills.CardTypeCode;
import com.aidong.model.wills.Upload;
import com.aidong.service.UploadService;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"cardType"})
public class CardTypeController extends BaseController {
    @Resource
    CardTypeCodeDao cardTypeCodeDao;
    @Resource
    CardManyUserDao cardManyUserDao;
    @Resource
    CardQuantityDao cardQuantityDao;
    @Resource
    CardShopLevelDao cardShopLevelDao;
    @Resource
    CardTimeLimitDao cardTimeLimitDao;
    @Resource
    DicTranCodeDao dicTranCodeDao;
    @Resource
    UploadService uploadService;

    public CardTypeController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return (new ModelAndView("card/type/list")).addObject("cardClass", this.getTypeList("cardClass")).addObject("cardCategory", this.getTypeList("cardCategory")).addObject("cardArea", this.getTypeList("cardArea"));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "name",required = false) String name, @RequestParam(value = "typeId",required = false) String typeId, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "manyShop",required = false) String manyShop, @RequestParam(value = "promotion",required = false) String promotion, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        cd.eq("typeId", typeId);
        cd.eq("manyShop", manyShop);
        ConditionMap mv;
        if(!this.chkNull(name)) {
            mv = new ConditionMap(1);
            mv.like("code", "%" + name + "%");
            mv.like("chName", "%" + name + "%");
            cd.addSub(mv);
        }

        if(!this.chkNullZ(status) && status.intValue() == 1) {
            cd.le("activeTime", new Date());
            cd.ge("inactiveTime", new Date());
        } else if(!this.chkNullZ(status) && status.intValue() == 2) {
            mv = new ConditionMap(1);
            mv.gt("activeTime", new Date());
            mv.lt("inactiveTime", new Date());
            cd.addSub(mv);
        }

        if(!this.chkNull(promotion)) {
            cd.eq("promotionCard", Integer.valueOf(1));
        }

        this.cardTypeCodeDao.queryPageList(pg, cd, (new OrderSet()).asc("code"));
        ModelAndView mv1 = new ModelAndView("card/type/_list");
        mv1.addObject("list", pg.getResultList());
        mv1.addObject("pg", pg);
        return mv1;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "name",required = false) String name, @RequestParam(value = "typeId",required = false) String typeId, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "manyShop",required = false) String manyShop, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, '\uea60');
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            cd.eq("typeId", typeId);
            cd.eq("manyShop", manyShop);
            ConditionMap xls;
            if(!this.chkNull(name)) {
                xls = new ConditionMap(1);
                xls.like("code", "%" + name + "%");
                xls.like("chName", "%" + name + "%");
                cd.addSub(xls);
            }

            if(!this.chkNullZ(status) && status.intValue() == 1) {
                cd.le("activeTime", new Date());
                cd.ge("inactiveTime", new Date());
            } else if(!this.chkNullZ(status) && status.intValue() == 2) {
                xls = new ConditionMap(1);
                xls.gt("activeTime", new Date());
                xls.lt("inactiveTime", new Date());
                cd.addSub(xls);
            }

            this.cardTypeCodeDao.queryPageList(e, cd, (new OrderSet()).asc("code"));
            ExportXls xls1 = new ExportXls(response, "卡种", "卡种");
            xls1.addHead(new String[]{"编号", "名称", "大类", "区域", "启用时间", "禁用时间", "卡价", "有效期", "有效期单位", "赠送日期", "停卡费", "转让费", "补卡费", "转店费", "续费折扣", "新合同", "升级", "续会", "优惠续会", "营销活动", "财务分类", "礼品卡", "健身计划", "PT课程", "赠品", "赠送1节私教课", "宝钢专用"});
            xls1.setWidth(new int[]{10, 20, 10, 20, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 30, 20});
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Iterator i$ = e.getResultList().iterator();

            while(i$.hasNext()) {
                CardTypeCode cardType = (CardTypeCode)i$.next();
                xls1.addRow(new Object[]{cardType.getCode(), cardType.getChName(), this.cache.getValue("cardClass", cardType.getTypeId()), cardType.getManyShop() + " - " + this.nvl(this.cache.getValue("cardArea", cardType.getManyShop())), sdf.format(cardType.getActiveTime()), sdf.format(cardType.getInactiveTime()), cardType.getPrice(), cardType.getValids(), this.cache.getValue("timeUnit", cardType.getValidUnit()), cardType.getAddValids() + this.nvl(this.cache.getValue("timeUnit", cardType.getAddValidUnit())), cardType.getStopFee(), cardType.getChangeFee(), cardType.getMendFee(), cardType.getChgShopFee(), cardType.getContDiscount(), this.chkNullZ(cardType.getSaleType1())?null:"√", this.chkNullZ(cardType.getSaleType2())?null:"√", this.chkNullZ(cardType.getSaleType3())?null:"√", this.chkNullZ(cardType.getPreferRenewal())?null:"√", this.chkNullZ(cardType.getPromotionCard())?null:"√", this.nvl(cardType.getTraCode()) + " - " + this.nvl(this.cache.getValue("tranCode", cardType.getTraCode())), this.chkNull(cardType.getGiftCardType())?"":this.nvl(this.cache.getValue("giftCardType", cardType.getGiftCardType())), cardType.getAmortizeFee2(), cardType.getAmortizeFee3(), cardType.getAmortizeFee4(), this.chkNullZ(cardType.getPresentPt())?null:"√", this.chkNullZ(cardType.getBaosteelUse())?null:"√"});
            }

            xls1.close();
            this.addUserLog("导出卡种", e.getResultList().size() + "条记录");
        } catch (Exception var12) {
            this.log.error("import", var12);
        }

        return null;
    }

    @RequestMapping({"add"})
    public ModelAndView add(@RequestParam(value = "code",required = false) String code) {
        ModelAndView mv = new ModelAndView("card/type/edit");
        CardTypeCode cardType = null;
        if(!this.chkNull(code)) {
            cardType = (CardTypeCode)this.cardTypeCodeDao.getById(code);
            if(cardType != null) {
                List timeList = this.cardTimeLimitDao.getCardTimeLimitList(cardType.getCode());
                List levelList = this.cardShopLevelDao.getCardShopLevelList(cardType.getCode());
                List quanList = this.cardQuantityDao.getCardQuantityList(cardType.getCode());
                List userList = this.cardManyUserDao.getCardManyUserList(cardType.getCode());
                cardType.setCode((String)null);
                Iterator i$ = timeList.iterator();

                while(i$.hasNext()) {
                    CardTimeLimit user = (CardTimeLimit)i$.next();
                    user.setAutoId((Integer)null);
                }

                i$ = levelList.iterator();

                while(i$.hasNext()) {
                    CardShopLevel user1 = (CardShopLevel)i$.next();
                    user1.setAutoId((Integer)null);
                }

                i$ = quanList.iterator();

                while(i$.hasNext()) {
                    CardQuantity user2 = (CardQuantity)i$.next();
                    user2.setAutoId((Integer)null);
                }

                i$ = userList.iterator();

                while(i$.hasNext()) {
                    CardManyUser user3 = (CardManyUser)i$.next();
                    user3.setAutoId((Integer)null);
                }

                mv.addObject("timeList", timeList);
                mv.addObject("levelList", levelList);
                mv.addObject("quanList", quanList);
                mv.addObject("userList", userList);
            }
        }

        if(cardType == null) {
            cardType = new CardTypeCode();
            cardType.setAddValids(Integer.valueOf(0));
            cardType.setOpenPeriod(Integer.valueOf(0));
            cardType.setDegree(Integer.valueOf(0));
            cardType.setManyShopQuantity(Integer.valueOf(0));
        }

        mv.addObject("cardType", cardType);
        mv.addObject("cardClass", this.getTypeList("cardClass"));
        mv.addObject("cardCategory", this.getTypeList("cardCategory"));
        mv.addObject("tranCode", this.dicTranCodeDao.getListByCategory("01"));
        mv.addObject("cardArea", this.getTypeList("cardArea"));
        mv.addObject("timeUnit", this.getTypeList("timeUnit"));
        mv.addObject("dayCode", this.getTypeList("dayCode"));
        mv.addObject("shopLevel", this.getTypeList("shopLevel"));
        mv.addObject("useType", this.getTypeList("cardUseType"));
        mv.addObject("giftCardType", this.getTypeList("giftCardType"));
        mv.addObject("_picPath", this.getSetting("pic.path"));
        mv.addObject("_oper", "add");
        return mv;
    }

    @RequestMapping({"_add"})
    @ResponseBody
    public String _add(@ModelAttribute("cardType") CardTypeCode cardType, @RequestParam(value = "times",required = false) String times, @RequestParam(value = "levels",required = false) String levels, @RequestParam(value = "quans",required = false) String quans, @RequestParam(value = "manyus",required = false) String manyus) {
        if(this.chkNull(cardType.getCode())) {
            return this.getResult(false, "请输入编码");
        } else if(this.chkNull(cardType.getChName())) {
            return this.getResult(false, "请输入名称");
        } else if(this.chkNull(cardType.getTypeId())) {
            return this.getResult(false, "请选择大类");
        } else if(this.cardTypeCodeDao.exists(cardType.getCode())) {
            return this.getResult(false, "编码已存在");
        } else {
            if(this.chkNull(cardType.getTimeLock())) {
                cardType.setTimeLock(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getDegreeLock())) {
                cardType.setDegreeLock(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getSaleType1())) {
                cardType.setSaleType1(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getSaleType2())) {
                cardType.setSaleType2(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getSaleType3())) {
                cardType.setSaleType3(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getPreferRenewal())) {
                cardType.setPreferRenewal(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getManyUser())) {
                cardType.setManyUser(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getTasteCard())) {
                cardType.setTasteCard(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getAllowUpdate())) {
                cardType.setAllowUpdate(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getDirectorCard())) {
                cardType.setDirectorCard(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getFixedType())) {
                cardType.setFixedType(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getMakeCard())) {
                cardType.setMakeCard(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getNoBusyCard())) {
                cardType.setNoBusyCard(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getAllowAddShop())) {
                cardType.setAllowAddShop(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getBarcodeUse())) {
                cardType.setBarcodeUse(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getBarcodeNoContract())) {
                cardType.setBarcodeNoContract(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getBarcodeContract())) {
                cardType.setBarcodeContract(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getPromotionCard())) {
                cardType.setPromotionCard(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getPresentPt())) {
                cardType.setPresentPt(Integer.valueOf(0));
            }

            if(this.chkNull(cardType.getBaosteelUse())) {
                cardType.setBaosteelUse(Integer.valueOf(0));
            }

            cardType.setCreateUser(this.getLoginUserCode());
            cardType.setCreateTime(new Date());
            cardType.setUpdateTime(new Date());
            List timeList = this.getTimeLimit(times);
            List levelList = this.getShopLevel(levels);
            List quanList = this.getQuantity(quans);
            List userList = this.getManyUser(manyus);
            if(timeList != null && levelList != null && quanList != null && userList != null) {
                try {
                    this.cardTypeCodeDao.addCardType(cardType, timeList, levelList, quanList, userList);
                    this.reloadTypeList("cardType");
                    this.addUserLog("新增卡种", "编号:" + cardType.getCode() + ",名称:" + cardType.getChName());
                } catch (Exception var11) {
                    this.log.error("add cardType", var11);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            } else {
                return this.getResult(false, "数据错误");
            }
        }
    }

    private List<CardTimeLimit> getTimeLimit(String times) {
        ArrayList list = new ArrayList();
        if(!this.chkNull(times)) {
            String[] ss = times.split("\\|");
            String[] arr$ = ss;
            int len$ = ss.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                String s1 = arr$[i$];
                String[] s = s1.split(",");
                Integer id = this.parseInt(s[0]);
                CardTimeLimit timeLimit;
                if(s.length == 2 && "-".equals(s[1]) && !this.chkNullZ(id)) {
                    timeLimit = new CardTimeLimit(id);
                    timeLimit.setCardTypeCode("-");
                } else {
                    if(s.length <= 4) {
                        return null;
                    }

                    timeLimit = new CardTimeLimit(id);
                    timeLimit.setDayId(s[1]);
                    timeLimit.setStatus(this.parseInt(s[2]));
                    timeLimit.setBeginTime(s[3]);
                    timeLimit.setEndTime(s[4]);
                }

                list.add(timeLimit);
            }
        }

        return list;
    }

    private List<CardShopLevel> getShopLevel(String times) {
        ArrayList list = new ArrayList();
        if(!this.chkNull(times)) {
            String[] ss = times.split("\\|");
            String[] arr$ = ss;
            int len$ = ss.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                String s1 = arr$[i$];
                String[] s = s1.split(",");
                Integer id = this.parseInt(s[0]);
                CardShopLevel shopLevel;
                if(s.length == 2 && "-".equals(s[1]) && !this.chkNullZ(id)) {
                    shopLevel = new CardShopLevel(id);
                    shopLevel.setCardTypeCode("-");
                } else {
                    if(s.length <= 2) {
                        return null;
                    }

                    shopLevel = new CardShopLevel(id);
                    shopLevel.setLevelCode(s[1]);
                    shopLevel.setDiscount(this.parseDouble(s[2]));
                }

                list.add(shopLevel);
            }
        }

        return list;
    }

    private List<CardQuantity> getQuantity(String times) {
        ArrayList list = new ArrayList();
        if(!this.chkNull(times)) {
            String[] ss = times.split("\\|");
            String[] arr$ = ss;
            int len$ = ss.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                String s1 = arr$[i$];
                String[] s = s1.split(",");
                Integer id = this.parseInt(s[0]);
                CardQuantity quantity;
                if(s.length == 2 && "-".equals(s[1]) && !this.chkNullZ(id)) {
                    quantity = new CardQuantity(id);
                    quantity.setCardTypeCode("-");
                } else {
                    if(s.length <= 3) {
                        return null;
                    }

                    quantity = new CardQuantity(id);
                    quantity.setAmount(this.parseInt(s[1]));
                    quantity.setAmount2(this.parseInt(s[2]));
                    quantity.setDiscount(this.parseDouble(s[3]));
                }

                list.add(quantity);
            }
        }

        return list;
    }

    private List<CardManyUser> getManyUser(String times) {
        ArrayList list = new ArrayList();
        if(!this.chkNull(times)) {
            String[] ss = times.split("\\|");
            String[] arr$ = ss;
            int len$ = ss.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                String s1 = arr$[i$];
                String[] s = s1.split(",");
                Integer id = this.parseInt(s[0]);
                CardManyUser manyUser;
                if(s.length == 2 && "-".equals(s[1]) && !this.chkNullZ(id)) {
                    manyUser = new CardManyUser(id);
                    manyUser.setCardTypeCode("-");
                } else {
                    if(s.length <= 3) {
                        return null;
                    }

                    manyUser = new CardManyUser(id);
                    manyUser.setUseType(s[1]);
                    manyUser.setUseQuantity(this.parseInt(s[2]));
                    manyUser.setFee(this.parseDouble(s[3]));
                    if(s.length > 4) {
                        manyUser.setCanAddPerson(this.parseInt(s[4]));
                    }

                    if(this.chkNull(manyUser.getCanAddPerson())) {
                        manyUser.setCanAddPerson(Integer.valueOf(0));
                    }
                }

                list.add(manyUser);
            }
        }

        return list;
    }

    @RequestMapping({"edit"})
    public ModelAndView edit(@RequestParam("code") String code) {
        CardTypeCode cardType = (CardTypeCode)this.cardTypeCodeDao.getById(code);
        if(cardType == null) {
            return this.showAlert("没有这个卡种");
        } else {
            List timeList = this.cardTimeLimitDao.getCardTimeLimitList(cardType.getCode());
            List levelList = this.cardShopLevelDao.getCardShopLevelList(cardType.getCode());
            List quanList = this.cardQuantityDao.getCardQuantityList(cardType.getCode());
            List userList = this.cardManyUserDao.getCardManyUserList(cardType.getCode());
            ModelAndView mv = new ModelAndView("card/type/edit");
            mv.addObject("cardType", cardType);
            mv.addObject("timeList", timeList);
            mv.addObject("levelList", levelList);
            mv.addObject("quanList", quanList);
            mv.addObject("userList", userList);
            mv.addObject("cardClass", this.getTypeList("cardClass"));
            mv.addObject("cardCategory", this.getTypeList("cardCategory"));
            mv.addObject("tranCode", this.dicTranCodeDao.getListByCategory("01"));
            mv.addObject("cardArea", this.getTypeList("cardArea"));
            mv.addObject("timeUnit", this.getTypeList("timeUnit"));
            mv.addObject("dayCode", this.getTypeList("dayCode"));
            mv.addObject("shopLevel", this.getTypeList("shopLevel"));
            mv.addObject("useType", this.getTypeList("cardUseType"));
            mv.addObject("giftCardType", this.getTypeList("giftCardType"));
            mv.addObject("_picPath", this.getSetting("pic.path"));
            mv.addObject("_oper", "edit");
            return mv;
        }
    }

    @RequestMapping({"_edit"})
    @ResponseBody
    public String _edit(@ModelAttribute("cardType") CardTypeCode cardType, @RequestParam(value = "times",required = false) String times, @RequestParam(value = "levels",required = false) String levels, @RequestParam(value = "quans",required = false) String quans, @RequestParam(value = "manyus",required = false) String manyus) {
        if(this.chkNull(cardType.getCode())) {
            return this.getResult(false, "没有这个卡种");
        } else if(this.chkNull(cardType.getChName())) {
            return this.getResult(false, "请输入名称");
        } else if(this.chkNull(cardType.getTypeId())) {
            return this.getResult(false, "请选择大类");
        } else {
            CardTypeCode cardType1 = (CardTypeCode)this.cardTypeCodeDao.getById(cardType.getCode());
            if(cardType1 == null) {
                return this.getResult(false, "没有这个卡种");
            } else {
                if(this.chkNull(cardType.getTimeLock())) {
                    cardType.setTimeLock(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getDegreeLock())) {
                    cardType.setDegreeLock(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getSaleType1())) {
                    cardType.setSaleType1(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getSaleType2())) {
                    cardType.setSaleType2(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getSaleType3())) {
                    cardType.setSaleType3(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getPreferRenewal())) {
                    cardType.setPreferRenewal(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getManyUser())) {
                    cardType.setManyUser(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getTasteCard())) {
                    cardType.setTasteCard(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getAllowUpdate())) {
                    cardType.setAllowUpdate(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getDirectorCard())) {
                    cardType.setDirectorCard(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getFixedType())) {
                    cardType.setFixedType(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getMakeCard())) {
                    cardType.setMakeCard(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getNoBusyCard())) {
                    cardType.setNoBusyCard(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getAllowAddShop())) {
                    cardType.setAllowAddShop(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getBarcodeUse())) {
                    cardType.setBarcodeUse(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getBarcodeNoContract())) {
                    cardType.setBarcodeNoContract(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getBarcodeContract())) {
                    cardType.setBarcodeContract(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getPromotionCard())) {
                    cardType.setPromotionCard(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getPresentPt())) {
                    cardType.setPresentPt(Integer.valueOf(0));
                }

                if(this.chkNull(cardType.getBaosteelUse())) {
                    cardType.setBaosteelUse(Integer.valueOf(0));
                }

                cardType.setCreateUser(cardType1.getCreateUser());
                cardType.setCreateTime(cardType1.getCreateTime());
                cardType.setUpdateTime(new Date());
                List timeList = this.getTimeLimit(times);
                List levelList = this.getShopLevel(levels);
                List quanList = this.getQuantity(quans);
                List userList = this.getManyUser(manyus);
                if(timeList != null && levelList != null && quanList != null && userList != null) {
                    try {
                        this.cardTypeCodeDao.updateCardType(cardType, timeList, levelList, quanList, userList);
                        this.reloadTypeList("cardType");
                        this.addUserLog("修改卡种", "编号:" + cardType.getCode() + ",名称:" + cardType.getChName());
                    } catch (Exception var12) {
                        this.log.error("edit dardType", var12);
                        return this.getResult(false, "保存发生错误");
                    }

                    return this.getResult(true, "保存完成");
                } else {
                    return this.getResult(false, "数据错误");
                }
            }
        }
    }

    @RequestMapping({"_del"})
    @ResponseBody
    public String _del(@RequestParam("code") String code) {
        CardTypeCode cardType = (CardTypeCode)this.cardTypeCodeDao.getById(code);
        if(cardType == null) {
            return this.getResult(false, "没有这个卡种");
        } else {
            try {
                this.cardTypeCodeDao.deleteById(code);
                this.reloadTypeList("cardType");
                this.addUserLog("删除卡种", "编号:" + cardType.getCode() + ",名称:" + cardType.getChName());
            } catch (Exception var4) {
                this.log.error("del cardType", var4);
                return this.getResult(false, "保存发生错误");
            }

            return this.getResult(true, "删除成功");
        }
    }

    @RequestMapping({"_upload"})
    @ResponseBody
    public String _upload(@RequestParam("file") MultipartFile file) {
        StringBuilder msg = new StringBuilder();
        Upload upload = this.uploadService.upload(file, msg);
        return upload == null?this.getResult(false, msg.toString()):this.getSuccess("{\"fid\":" + upload.getFileId() + ",\"furl\":\"" + upload.getUrl() + "\"}", "上传成功");
    }
}

